package com.whoimi.common;

import org.slf4j.helpers.MessageFormatter;

public class BusiException extends RuntimeException {

    private Integer errorCode = ResultInfo.Constant.CODE_FAIL;
    private String errorMessage;

    public BusiException(String errorMessage) {
        super(errorMessage);
        this.errorMessage = errorMessage;

    }

    public BusiException(String errorMessage, Object... args) {
        super(MessageFormatter.arrayFormat(errorMessage, args).getMessage());
        this.errorMessage = MessageFormatter.arrayFormat(errorMessage, args).getMessage();

    }

    public BusiException(Integer errorCode, String errorMessage) {
        super(errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public BusiException(Integer errorCode, String errorMessage, Object... args) {
        super(MessageFormatter.arrayFormat(errorMessage, args).getMessage());
        this.errorCode = errorCode;
        this.errorMessage = MessageFormatter.arrayFormat(errorMessage, args).getMessage();

    }

    public BusiException(ResultInfo.ResultEnum resultEnum) {
        this(resultEnum.getResultCode(), resultEnum.getResultMsg());
    }

    public BusiException(ResultInfo.ResultEnum resultEnum, Object... args) {
        this(resultEnum.getResultCode(), MessageFormatter.arrayFormat(resultEnum.getResultMsg(), args).getMessage());

    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }


    @Override
    public String toString() {
        return "BusinessException{" +
                "errorCode='" + errorCode + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                '}';
    }
}
